#include "ButtonGroup.h"
#include "ui_ButtonGroup.h"
#include "MyButton.h"

ButtonGroup::ButtonGroup(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::ButtonGroup)
{
    ui->setupUi(this);
}

ButtonGroup::~ButtonGroup()
{
    delete ui;
}

void ButtonGroup::initButtons()
{
    // 开始游戏
    ui->startBtn->setImage(":/images/start-1.png",":/images/start-2.png",":/images/start-3.png");
    //出牌
    ui->playCardBtn->setImage(":/images/chupai_btn-1.png",":/images/chupai_btn-2.png",":/images/chupai_btn-3.png");
    ui->playCardBtn_2->setImage(":/images/chupai_btn-1.png",":/images/chupai_btn-2.png",":/images/chupai_btn-3.png");
    //放弃
    ui->passBtn->setImage(":/images/pass_btn-1.png",":/images/pass_btn-2.png",":/images/pass_btn-3.png");
    //不抢
    ui->giveUpBtn->setImage(":/images/buqiang-1.png",":/images/buqiang-2.png",":/images/buqiang-3.png");
    //1,2,3分
    ui->oneScoreBtn->setImage(":/images/1fen-1.png",":/images/1fen-2.png",":/images/1fen-3.png");
    ui->twoScoreBtn->setImage(":/images/2fen-1.png",":/images/2fen-2.png",":/images/2fen-3.png");
    ui->threeScoreBtn->setImage(":/images/3fen-1.png",":/images/3fen-2.png",":/images/3fen-3.png");

    //设置按钮的大小
    QVector<MyButton*> btns;
    btns << ui->startBtn << ui->playCardBtn << ui->playCardBtn_2 << ui->passBtn
         << ui->giveUpBtn << ui->oneScoreBtn << ui->twoScoreBtn << ui->threeScoreBtn;
    for(MyButton* it: btns){
        it->setFixedSize(90,45);
    }
    connect(ui->startBtn,&MyButton::clicked,this,&ButtonGroup::startGame);
    connect(ui->playCardBtn,&MyButton::clicked,this,&ButtonGroup::playHand);
    connect(ui->playCardBtn_2,&MyButton::clicked,this,&ButtonGroup::playHand);
    connect(ui->passBtn,&MyButton::clicked,this,&ButtonGroup::pass);
    connect(ui->giveUpBtn,&MyButton::clicked,this,[=](){ emit betPoint(0); });
    connect(ui->oneScoreBtn,&MyButton::clicked,this,[=](){ emit betPoint(1); });
    connect(ui->twoScoreBtn,&MyButton::clicked,this,[=](){ emit betPoint(2); });
    connect(ui->threeScoreBtn,&MyButton::clicked,this,[=](){ emit betPoint(3); });
}

void ButtonGroup::selectPanel(Panel page, int bet)
{
    ui->stackedWidget->setCurrentIndex((int)page);
    if(page != CallLord){
        return;
    }
    if(bet == 0){
        ui->oneScoreBtn->setVisible(true);
        ui->twoScoreBtn->setVisible(true);
        ui->threeScoreBtn->setVisible(true);
    }else if(bet == 1){
        ui->oneScoreBtn->setVisible(false);
        ui->twoScoreBtn->setVisible(true);
        ui->threeScoreBtn->setVisible(true);
    }else if(bet == 2){
        ui->oneScoreBtn->setVisible(false);
        ui->twoScoreBtn->setVisible(false);
        ui->threeScoreBtn->setVisible(true);
    }
}

